#!/usr/bin/perl
#What do I want to do? Light weight password cracker that you can take to
#any system. MD5 Hashes only at the moment.
#GGF Stands for Glorified Grep Function.
use Digest::MD5 'md5_hex';
use Digest::SHA1 'sha1_hex';
use warnings;
use Cwd;
$count = 0;
$count2 = 1;
$wspace = 0;
$flycompute = 1;
$pwd = &Cwd::cwd();
$ppath = "$pwd/BrokenPerl.pot";
&Banner;
&c();


sub Banner {
    print "
    >=>>=>                       >=>                                >======>                      >=>
    >>   >=>                     >=>                                >=>    >=>                    >=>
    >>    >=> >> >==>    >=>     >=>  >=>   >==>    >==>>==>        >=>    >=>   >==>    >> >==>  >=>
    >==>>=>    >=>     >=>  >=>  >=> >=>  >>   >=>   >=>  >=>       >======>   >>   >=>   >=>     >=>
    >>    >=>  >=>    >=>    >=> >=>=>    >>===>>=>  >=>  >=>       >=>        >>===>>=>  >=>     >=>
    >>     >>  >=>     >=>  >=>  >=> >=>  >>         >=>  >=>       >=>        >>         >=>     >=>
    >===>>=>  >==>       >=>     >=>  >=>  >====>   >==>  >=>       >=>         >====>   >==>    >==>
    
     _____         _      _____                     _ _
    |  |  |___ ___| |_   |     |___ _____ _____ ___|_| |_ _ _
    |     | . |  _|  _|  |   --| . |     |     |   | |  _| | |
    |__|__|__ |___|_^_|  |_____|___|_|_|_|_|_|_|_|_|_|_| |_  |
                                                         |___|
    
||What does this do you ask? Well, I respond, it has two functions. The first to generate a list of hashes from a password list to make the password cracking process more efficant. The second is to use that big list of hashes to crack a hash at pretty fast speeds. It can only crack one hash at at time but Ill update it, dont worry. I made this in perl because I wanted to make a project in perl and I thought this would be fun. It can actually crack pretty fast. What it will do is spit out a line number so you can relate that back to your Plaintext list. CURRENTLY this only cracks Md5 hashes. Later it will crack much more. Its fast because it doesnt have to generate the hashes in real time. Perl has a hard time with HUGE files. I tried to use a 2gb file and just couldnt get it to load. I made this compleatly in nano. I also intend to add a gui to it for those not yet comfterable with the CLI.||
        
Version: 0.4 Alpha
        
|By the Gentleman of Science|\n";
        }
sub c() {
    print "(1) Digest Plaintext (2) MiniRIP\n";
    chomp($choice = <>);
    if ($choice == 2) {
        &MRIP
    }
    if ($choice == 1) {
        &DP
    }
}

sub MRIP {
    $flycompute = 1;
    print "MD5/SHA1 (It will autodetect) Hash you wish to crack:\n";
    chomp($hashf = <>);
    print "Password List (Hashes):\n";
    chomp($wlist = <>);
    open(FILE, "$wlist") or die("Unable to open file");
    while(my $linelis=<FILE>){
        push (@wordlis, $linelis);
    }
    #@wordlis = <FILE>;
    close(FILE);
    $lines = @wordlis;
    unless(open POT, '>'.$ppath) {
        die "Unable to create POT";
    }
    print "$lines\n";
    print "Verifying hashes... \n";
    $sha1 = grep(/\b([0-9a-f]{40})\b/, @wordlis);
    $iiah = grep(/^[0-9a-f]{32}$/i, @wordlis);
    $sha1h = grep(/\b([0-9a-f]{40})\b/, $hashf);
    $iiahh = grep(/^[0-9a-f]{32}$/i, $hashf);
    if (($iiah != 0) || ($sha1 != 0)) {
        print "Yep its already hashed! Good to go.\n";
        print "Hash: $hashf\n";
        if ($iiah>0) {
            print "Your hashes are Md5...\n";
            if ($sha1h>0) {
                print "Though, your hash you wish to crack is an Sha1 hash. Please correct this.\n";
            }
            else {
                &GGF
            }
        }
        if ($sha1>0) {
            print "Your hashes are Sha1...\n";
            if ($iiahh>0) {
                print "Though, your hash you wish to crack is an Md5 hash. Please correct this.\n";
            }
            else {
                &GGF
            }
        }
    }
    else {
        print "This is plaintext instead of hashes. Would you like to (1) convert to hashes (2) real time convert: \n";
        chomp($flycompute = <>);
        if ($flycompute == 1) {
            print "Your passwords are not in hashed form. They will be converted and saved for later use\n";
            print "Path to Output: ";
            chomp($outfile = <>);
            unless(open OUTFILE, '>'.$outfile) {
                die "Unable to create $outfile";
            }
        print "Converting to hashes...\n";
        &Conver
        }
        else {
            &GGF
        }
    }
}
sub GGF {
    $sha1h = grep(/\b([0-9a-f]{40})\b/, $hashf);
    $iiahh = grep(/^[0-9a-f]{32}$/i, $hashf);
    $hashf =~ s/^\s+|\s+$//g;
    $count = 0;
    $count2 = 1;
    foreach $line (@wordlis) {
        $currenth = @wordlis[$count];
        if ($flycompute != 1) {
            if ($sha1h != 0) {
                $currenth = sha1_hex($currenth);
            }
            if ($iiahh != 0) {
                $currenth = md5_hex($currenth);
            }
        }
        $currenth =~ s/^\s+|\s+$//g;
        if ($count2 == 50000) {
            $count2 = 0;
            $perc = $count/$lines;
            print $perc*100;
            print "%\n";
        }
        if ($hashf eq $currenth) {
            if ($flycompute != 1) {
                print "Line: $count Hash: $hashf Plaintext: @wordlis[$count]";
                print POT "Line: $count Hash: $hashf Plaintext: @wordlis[$count]\n";
            }
            else {
                print "Line: $count Hash: $hashf\n";
                print POT "Line: $count Hash: $hashf\n";
            }
        }
        $count2++;
        $count++;
    }
}
sub DP {
    print "Enter File Name:\n ";
    chomp($filename = <>);
    open(FILE, "$filename") or die("Unable to open file");
    while(my $linelis=<FILE>){
        push (@wordlis, $linelis);
    }
    print "Path to Output: ";
    chomp($outfile = <>);
    unless(open OUTFILE, '>'.$outfile) {
        die "Unable to create $outfile";
    }
    print "(1) Md5 (2) Sha1\n";
    chomp($htype = <>);
    close(FILE);
    &Conver
}
sub Conver {
    $lines = @wordlis;
    print "$lines\n";
    $count = 0;
    $count2 = 1;
    foreach $line (@wordlis) {
        if ($count2 == 50000) {
            $count2 = 0;
            $perc = $count/$lines;
            print $perc*100;
            print "%\n";
        }
        $count2++;
        $count++;
        if ($htype == 1) {
            $hash = md5_hex($line);
        }
        else {
            $hash = sha1_hex($line);
        }
        $hash =~ s/^\s+|\s+$//g;
        print OUTFILE "$hash\n";
    }
    close(OUTFILE);
    print "(1) Exit (2) MiniRIP\n";
    chomp($choice2 = <>);
    if ($choice2 == 2) {
        &MRIP
    }
    if ($choice2 == 1) {
        
    }
}